﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Ket_noi_toi_VPP_bang_mo_hinh_ba_lop.Connection;

namespace Ket_noi_toi_VPP_bang_mo_hinh_ba_lop.DAL
{
    class NhanVien
    {
        private dbConnection Conn;

        public NhanVien()
        {
            Conn = new dbConnection();
        }

        public bool Insert(string HoTen,DateTime NgaySinh,string DienThoai,string DiaChi,string GioiTinh,string TenDN,string Pass,string QuyenDN)
        { 
            SqlParameter[] sqlPara=new SqlParameter[8];            
            sqlPara[0] = new SqlParameter("@HoTen",SqlDbType.NVarChar,50);                        
            sqlPara[0].Value = Convert.ToString(HoTen);
            sqlPara[1] = new SqlParameter("@NgaySinh",SqlDbType.Date);                        
            sqlPara[1].Value = NgaySinh;
            sqlPara[2] = new SqlParameter("@DienThoai", SqlDbType.VarChar,20);
            sqlPara[2].Value = Convert.ToString(DienThoai);            
            sqlPara[3] = new SqlParameter("@DiaChi", SqlDbType.NVarChar,50);
            sqlPara[3].Value = Convert.ToString(DiaChi);           
            sqlPara[4] = new SqlParameter("@GioiTinh", SqlDbType.Char,7);
            sqlPara[4].Value = Convert.ToString(GioiTinh);           
            sqlPara[5] = new SqlParameter("@TenDN", SqlDbType.NVarChar,20);
            sqlPara[5].Value = Convert.ToString(TenDN);            
            sqlPara[6] = new SqlParameter("@Pass", SqlDbType.VarChar,20);
            sqlPara[6].Value = Convert.ToString(Pass);
            sqlPara[7] = new SqlParameter("@QuyenDN", SqlDbType.VarChar, 20);
            sqlPara[7].Value = Convert.ToString(QuyenDN);
            return Conn.executeInsertProcedureQuery("Insert_NhanVien", sqlPara);
        }

        public bool Update(int MaNV, string HoTen,DateTime NgaySinh,string DienThoai,string DiaChi,string GioiTinh,string TenDN,string Pass,string QuyenDN)
        {
            SqlParameter[] sqlPara=new SqlParameter[9];
            sqlPara[0] = new SqlParameter("@MaNV",SqlDbType.Int);
            sqlPara[0].Value = MaNV;            
            sqlPara[1] = new SqlParameter("@HoTen",SqlDbType.NVarChar,50);                        
            sqlPara[1].Value = Convert.ToString(HoTen);
            sqlPara[2] = new SqlParameter("@NgaySinh",SqlDbType.Date);                        
            sqlPara[2].Value = NgaySinh;
            sqlPara[3] = new SqlParameter("@DienThoai", SqlDbType.VarChar,20);
            sqlPara[3].Value = Convert.ToString(DienThoai);            
            sqlPara[4] = new SqlParameter("@DiaChi", SqlDbType.NVarChar,50);
            sqlPara[4].Value = Convert.ToString(DiaChi);           
            sqlPara[5] = new SqlParameter("@GioiTinh", SqlDbType.Char,7);
            sqlPara[5].Value = Convert.ToString(GioiTinh);
            sqlPara[6] = new SqlParameter("@TenDN", SqlDbType.NVarChar, 20);
            sqlPara[6].Value = Convert.ToString(TenDN);            
            sqlPara[7] = new SqlParameter("@Pass", SqlDbType.VarChar,20);
            sqlPara[7].Value = Convert.ToString(Pass);
            sqlPara[8] = new SqlParameter("@Quyen", SqlDbType.VarChar, 20);
            sqlPara[8].Value = Convert.ToString(QuyenDN);
            return Conn.executeUpdateProcedureQuery("Update_NV", sqlPara);
        }
        
        public bool Delete(int MaNV)
        { 
            SqlParameter[] sqlPara=new SqlParameter[1];
            sqlPara[0] = new SqlParameter("@MaNV",SqlDbType.Int);
            sqlPara[0].Value = MaNV;
            return Conn.executeUpdateProcedureQuery("Delete_NhanVien",sqlPara);
        }
        
        public DataTable SelectAll()
        {
            return Conn.excuteSelectProcedureQuery("SelectAll_NhanVien");
        }

        public DataTable SelectID(int MaNV)
        { 
            SqlParameter[] sqlPara=new SqlParameter[1];
            sqlPara[0] = new SqlParameter("@MaNV",SqlDbType.Int);
            sqlPara[0].Value = MaNV;
            return Conn.excuteSelectProcedureQuery("SelectID_NhanVien",sqlPara);
        }
    }
}
